<script setup>
const props = defineProps({
  dish: {
    type: Object,
    default: () => ({
      id: null,
      image: '',
      dishName: '',
      merchant: '',
      price: '',
      calorie: ''
    })
  }
})

// 跳转到菜品详情页
const goToDishDetail = () => {
  uni.navigateTo({
    url: `/pages/DishDetail/index?dishId=${props.dish.id}`
  })
}

</script>

<template>
  <view class="dish-item-container"  @tap="goToDishDetail">
    <view class="dish-img-wrapper">
      <image
        :src="dish.image || '/static/images/default.png'"
        class="dish-image"
        mode="aspectFill"
      />
    </view>
    <view class="dish-details">
      <text class="dish-name">{{ dish.dishName || '未知菜品' }}</text>
      <view class="dish-meta">
        <text class="dish-shop" v-if="dish.merchant">
          <text class="iconfont icon-shangpu"></text>
          {{ dish.merchant }}
        </text>
        <text class="dish-location" v-if="dish.location">
          <text class="iconfont icon-weizhi"></text>
          {{ dish.location }}
        </text>
        <text class="dish-rating" v-if="dish.dishRating">
          <text class="iconfont icon-icon"></text>
          {{ dish.dishRating.toFixed(1) }}分 ({{ dish.ratingCount }}人评价)
        </text>
      </view>
      <view class="dish-extra">
        <text class="dish-price" v-if="dish.price">￥{{ dish.price }}</text>
        <text class="dish-heat" v-if="dish.calorie">热量: {{ dish.calorie }}千卡</text>
      </view>
    </view>
  </view>
</template>

<style scoped lang="scss">
.dish-item-container {
  display: flex;
  flex-direction: row;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 32rpx;
  box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.08);
  padding: 32rpx;
  width: 100%;
  box-sizing: border-box;
  transition: box-shadow 0.2s;
  border: 3rpx solid rgba(102, 126, 234, 0.08);
  position: relative;
  
  &:active {
    box-shadow: 0 16rpx 64rpx rgba(102, 126, 234, 0.18);
    border-color: #667eea44;
  }
}

.dish-img-wrapper {
  width: 160rpx;
  height: 160rpx;
  border-radius: 24rpx;
  overflow: hidden;
  background: #fff;
  margin-right: 32rpx;
  box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dish-image {
  width: 100%;
  height: 100%;
  border-radius: 24rpx;
  background: #f5f7fa;
}

.dish-details {
  flex: 1;
  text-align: left;
}

.dish-name {
  font-size: 36rpx;
  font-weight: 600;
  color: #333;
  margin: 0 0 16rpx 0;
  background: linear-gradient(45deg, #667eea, #764ba2);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: block;
}

.dish-meta {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
  font-size: 28rpx;
  color: #666;
  margin-bottom: 12rpx;

  .dish-shop {
    display: flex;
    align-items: center;
    gap: 8rpx;
    
    .iconfont {
      font-size: 24rpx;
      color: #667eea;
    }
  }

  .dish-location {
    display: flex;
    align-items: center;
    gap: 8rpx;
    color: #409eff;
    .iconfont {
      font-size: 24rpx;
      color: #409eff;
    }
  }

  .dish-rating {
    display: flex;
    align-items: center;
    gap: 8rpx;
    color: #ffa500;
    
    .iconfont {
      font-size: 24rpx;
    }
  }
}

.dish-extra {
  display: flex;
  justify-content: flex-start;
  gap: 24rpx;
  font-size: 28rpx;
  color: #888;
  margin-top: 4rpx;
  flex-wrap: wrap;
}

.dish-price {
  color: #e85d5d;
  font-weight: 500;
}

.dish-heat {
  color: #409eff;
}

/* 小程序样式适配 */
/* #ifdef MP-WEIXIN */
.dish-item-container {
  background: rgba(255, 255, 255, 0.98) !important;
  backdrop-filter: none !important;
  box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.06) !important;
}

.dish-name {
  color: #667eea !important;
  background: none !important;
  background-clip: unset !important;
  -webkit-background-clip: unset !important;
  -webkit-text-fill-color: unset !important;
}
/* #endif */

// 平板适配
@media (min-width: 768px) {
  .dish-item-container {
    padding: 40rpx;
  }
  
  .dish-img-wrapper {
    width: 200rpx;
    height: 200rpx;
    margin-right: 40rpx;
  }
  
  .dish-name {
    font-size: 40rpx;
  }
  
  .dish-meta {
    font-size: 30rpx;
    gap: 32rpx;
  }
  
  .dish-extra {
    font-size: 30rpx;
    gap: 32rpx;
  }
}
</style>
